const flv = window.flvjs
const u = navigator.userAgent, app = navigator.appVersion, ua = navigator.userAgent.toLowerCase()
export	let isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);               //ios终端
export	let isWeixin = ua.match(/MicroMessenger/i) == "micromessenger";       //是否微信  
export	let isqq = u.match(/\sQQ/i) == " QQ";
export	let isAndroid = u.indexOf('Android') > -1 || u.indexOf('Linux') > -1;
export  let isHuwei = navigator.userAgent.toLowerCase().indexOf('huawei') > -1 || navigator.userAgent.toLowerCase().indexOf('honor') > -1
export let flvCommon = (function(){
	let flvSupport = (function(){
		let flvSuppot
		flvSuppot = flv.getFeatureList().mseLiveFlvPlayback && !isIOS
		return flvSuppot;
	})()
	let createFlvPlayer = function(url,videoElement){
    let flvPlayer = flv.createPlayer({
      type: 'flv',
      url: url
	},{
        enableWorker: true,
        enableStashBuffer: false,
        stashInitialSize: 128,
		});
    flvPlayer.attachMediaElement(videoElement);
    return flvPlayer;
	}
	let destroyFlvPlayer = function(flvPlayer,flvPlayerPlaying){
		flvPlayer.pause();
    flvPlayer.unload();
		flvPlayer.detachMediaElement();
		flvPlayer.destroy();
	}
	return{
		flvSupport:flvSupport,
		createFlvPlayer:createFlvPlayer,
		destroyFlvPlayer:destroyFlvPlayer,
	}
})()
export function toggleClass(element, className) {
  if (!element || !className) {
    return
  }
  let classString = element.className
  const nameIndex = classString.indexOf(className)
  if (nameIndex === -1) {
    classString += '' + className
  } else {
    classString =
      classString.substr(0, nameIndex) +
      classString.substr(nameIndex + className.length)
  }
  element.className = classString
}
export function hasClass(ele, cls) {
  return !!ele.className.match(new RegExp('(\\s|^)' + cls + '(\\s|$)'))
}
export function addClass(ele, cls) {
  if (!hasClass(ele, cls)) ele.className += ' ' + cls
}
export function removeClass(ele, cls) {
  if (hasClass(ele, cls)) {
    const reg = new RegExp('(\\s|^)' + cls + '(\\s|$)')
    ele.className = ele.className.replace(reg, ' ')
  }
}